package com.hdcx.Minfresh.adapter;


import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hdcx.Minfresh.R;
import com.hdcx.Minfresh.bean.OrderDetailWrapper;
import com.hdcx.Minfresh.holder.MainHolder;
import com.hdcx.Minfresh.util.AppUtil;

import cn.lemon.view.adapter.BaseViewHolder;

/**
 * Created by Administrator on 2016/11/9.
 */

public class OrderDetailAdapter extends RecyclerView.Adapter<OrderDetailAdapter.DetailOrderHolder> {
    FragmentActivity mActivity;
    OrderDetailWrapper data;

    public OrderDetailAdapter(FragmentActivity mActivity) {
        this.mActivity = mActivity;
    }

    @Override
    public DetailOrderHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        LayoutInflater layoutInflater = LayoutInflater.from(mActivity);
        if(viewType == 0){
            view = layoutInflater.inflate(R.layout.item_fragment_order_detail_one, parent, false);
        }else if(viewType==data.getGlist().size()+1){
            view = layoutInflater.inflate(R.layout.item_fragment_order_detail_three, parent, false);
        }else{
            view = layoutInflater.inflate(R.layout.item_activity_collect, parent, false);
        }
        return new DetailOrderHolder(view);
    }

    @Override
    public void onBindViewHolder(DetailOrderHolder holder, int position) {
      if(position==0){
          holder.tv_person.setText("收货人:"+data.getAddress().getName());
          holder.tv_phone.setText(data.getAddress().getMobile());
          holder.tv_address.setText(data.getAddress().getAddress());
          AppUtil.showPic(data.getOrder().getStaus_img(),holder.img_style);
          holder.tv_style.setText(data.getOrder().getStatus_msg());
          holder.tv_info.setText(data.getOrder().getStatus_info());
      }else if(position==data.getGlist().size()+1){
          holder.tv_ddbh.setText(data.getOrder().getOrder_sn());
          holder.tv_bz.setText(data.getOrder().getNotes().equals("")?"未填写":data.getOrder().getNotes());
          holder.tv_xdsj.setText(data.getOrder().getAdd_time());
          holder.tv_zffs.setText(data.getOrder().getPayname());
          holder.tv_jylsh.setText(data.getOrder().getOut_trade_sn());
           holder.tv_totle_money.setText("￥"+data.getOrder().getGoods_amount());
           holder.tv_realy_money.setText("￥"+data.getOrder().getOrder_amount());
      }else{
          int temp =position-1;
          OrderDetailWrapper.Glist item = data.getGlist().get(temp);
          AppUtil.showPic(item.getGoods_img(),holder.img_main);
          holder.tv_name.setText(item.getGoods_title());
          holder.tv_intro.setText(item.getGoods_title());
          holder.tv_intro_2.setText("规格："+item.getGoods_etalon()+item.getGoods_units());
          holder.tv_money.setText("￥"+item.getGoods_price()+"/"+item.getGoods_units());
          holder.tv_units.setText(item.getOrder_quantity()+item.getGoods_units());
      }
    }

    @Override
    public int getItemCount() {
        if(data==null){
            return 0;
        }
        return data.getGlist().size()+2;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    public void setData(OrderDetailWrapper response) {
        data = response;
        notifyDataSetChanged();
    }

    public class DetailOrderHolder extends BaseViewHolder {
        ImageView img_main,img_style;
        TextView tv_name,tv_intro,tv_intro_2,tv_units,tv_money,tv_person,tv_phone,tv_address,tv_style,tv_info;
        TextView tv_bz,tv_totle_money,tv_realy_money,tv_xdsj,tv_ddbh,tv_zffs,tv_jylsh;

        public DetailOrderHolder(View itemView) {
            super(itemView);

            tv_name = (TextView) itemView.findViewById(R.id.tv_name);
            tv_style = (TextView) itemView.findViewById(R.id.tv_style);
            tv_intro = (TextView) itemView.findViewById(R.id.tv_intro);
            tv_info = (TextView) itemView.findViewById(R.id.tv_info);
            tv_intro_2 = (TextView) itemView.findViewById(R.id.tv_intro_2);
            tv_units = (TextView) itemView.findViewById(R.id.tv_units);
            tv_money = (TextView) itemView.findViewById(R.id.tv_money);
            tv_person = (TextView) itemView.findViewById(R.id.tv_person);
            tv_phone = (TextView) itemView.findViewById(R.id.tv_phone);
            img_main = (ImageView) itemView.findViewById(R.id.img_main);
            img_style = (ImageView) itemView.findViewById(R.id.img_style);
            tv_address = (TextView) itemView.findViewById(R.id.tv_address);
            tv_bz = (TextView) itemView.findViewById(R.id.tv_bz);
            tv_totle_money = (TextView) itemView.findViewById(R.id.tv_totle_money);
            tv_realy_money = (TextView) itemView.findViewById(R.id.tv_realy_money);
            tv_xdsj = (TextView) itemView.findViewById(R.id.tv_xdsj);
            tv_ddbh = (TextView) itemView.findViewById(R.id.tv_ddbh);
            tv_zffs = (TextView) itemView.findViewById(R.id.tv_zffs);
            tv_jylsh = (TextView) itemView.findViewById(R.id.tv_jylsh);
        }
    }
}
